"use strict";
cc._RF.push(module, '32866zsZrRJ2Iti/buA2qW2', 'GbzSdkManager');
// scripts/manager/GbzSdkManager.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var GbzAudioManager_1 = require("./GbzAudioManager");
var GbzSdkManager = /** @class */ (function () {
    function GbzSdkManager() {
        this.share_title = '熬夜打螺丝，过不了第二关，谁来帮帮我呀？';
        this.ad_video = null;
        this.ad_inter = null;
        this.ad_banner = null;
        this.ad_custom_row = null;
        this.ad_customer_col = null;
        this.ad_video_id = '41eummgs5o76lmt6n6';
        this.ad_inter_id = '41eummgs5o76lmt6n6';
        this.ad_banner_id = '41eummgs5o76lmt6n6';
        this.ad_custom_row_id = '';
        this.ad_custom_col_id = '';
    }
    GbzSdkManager.getIns = function () {
        if (this._ins === null) {
            this._ins = new GbzSdkManager();
            this._ins.init();
        }
        return this._ins;
    };
    Object.defineProperty(GbzSdkManager, "ins", {
        get: function () {
            return this.getIns();
        },
        enumerable: false,
        configurable: true
    });
    GbzSdkManager.prototype.platform = function () {
        var platform = null;
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            platform = window['wx'];
        }
        else if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
            platform = window['tt'];
        }
        return platform;
    };
    GbzSdkManager.prototype.init = function () {
        this.passiveShare();
        this.getRank();
        this.initAudioEnd();
        this.initBanner();
        this.initInter();
        this.initVideo();
        this.initCustomCol();
        this.initCustomRow();
    };
    GbzSdkManager.prototype.activeShare = function (title) {
        var platform = this.platform();
        if (!platform)
            return;
        title = title || this.share_title;
        platform.shareAppMessage({ title: title });
    };
    GbzSdkManager.prototype.passiveShare = function (title) {
        var platform = this.platform();
        if (!platform)
            return;
        platform.showShareMenu({
            success: function (res) { },
            fail: function (res) { }
        });
        title = title || this.share_title;
        platform.onShareAppMessage(function () {
            return { title: title };
        });
    };
    GbzSdkManager.prototype.initAudioEnd = function () {
        if (typeof window['wx'] === 'undefined')
            return;
        window['wx'].onAudioInterruptionEnd(function () {
            GbzAudioManager_1.default.ins.play();
        });
    };
    GbzSdkManager.prototype.initBanner = function () {
        var _this = this;
        var platform = this.platform();
        if (!platform)
            return;
        if (this.ad_banner_id == '')
            return;
        var size = platform.getSystemInfoSync();
        if (this.ad_banner == null) {
            this.ad_banner = platform.createBannerAd({
                adUnitId: this.ad_banner_id,
                adIntervals: 30,
                style: {
                    height: size.windowHeight - 80,
                    left: 0,
                    top: 500,
                    width: size.windowWidth
                }
            });
            this.ad_banner.onResize(function (res) {
                _this.ad_banner.style.top = size.windowHeight - _this.ad_banner.style.realHeight;
                _this.ad_banner.style.left = size.windowWidth / 2 - _this.ad_banner.style.realWidth / 2;
            });
            this.ad_banner.onError(function (err) { });
        }
    };
    GbzSdkManager.prototype.showBanner = function (bool) {
        var platform = this.platform();
        if (!platform)
            return;
        if (this.ad_banner) {
            bool ? this.ad_banner.show() : this.ad_banner.hide();
        }
    };
    GbzSdkManager.prototype.initInter = function () {
        var platform = this.platform();
        if (!platform)
            return;
        if (this.ad_inter_id == '')
            return;
        if (this.ad_inter == null) {
            this.ad_inter = platform.createInterstitialAd({
                adUnitId: this.ad_inter_id
            });
            this.ad_inter.onError(function (err) { });
        }
    };
    GbzSdkManager.prototype.showInter = function () {
        var platform = this.platform();
        if (!platform)
            return;
        if (this.ad_inter) {
            this.ad_inter.show().catch(function (err) { });
        }
    };
    GbzSdkManager.prototype.initVideo = function () {
        var platform = this.platform();
        if (!platform)
            return;
        if (this.ad_video_id == '')
            return;
        if (this.ad_video == null) {
            this.ad_video = platform.createRewardedVideoAd({
                adUnitId: this.ad_video_id
            });
            this.ad_video.onError(function (err) { });
        }
    };
    GbzSdkManager.prototype.showVideo = function (success, fail) {
        var _this = this;
        var platform = this.platform();
        if (!platform)
            return success && success('模拟成功，激励奖励已发放');
        if (this.ad_video) {
            this.ad_video.offClose();
            this.ad_video.onClose(function (res) {
                _this.ad_video.offClose();
                if (res && res.isEnded || res === undefined) {
                    return success && success('激励奖励已发放');
                }
                else {
                    return fail && fail('视频播放中断');
                }
            });
            this.ad_video.show().catch(function () {
                _this.ad_video.load()
                    .then(function () { return _this.ad_video.show(); })
                    .catch(function (err) {
                    console.log('广告展示失败');
                });
            });
        }
        else {
            return fail && fail('该功能尚未开放');
        }
    };
    GbzSdkManager.prototype.initCustomRow = function () {
        var platform = this.platform();
        if (!platform)
            return;
        if (this.ad_custom_row_id == '')
            return;
        var size = platform.getSystemInfoSync();
        if (this.ad_custom_row == null) {
            this.ad_custom_row = platform.createCustomAd({
                adUnitId: this.ad_custom_row_id,
                adIntervals: 30,
                style: {
                    width: 320,
                    left: (size.screenWidth - 320) / 2,
                    top: size.screenHeight - 100,
                    fixed: 0
                }
            });
            this.ad_custom_row.onError(function (err) { });
        }
    };
    GbzSdkManager.prototype.showCustomRow = function (bool) {
        if (bool === void 0) { bool = true; }
        var platform = this.platform();
        if (!platform)
            return;
        if (this.ad_custom_row)
            bool ? this.ad_custom_row.show() : this.ad_custom_row.hide();
    };
    GbzSdkManager.prototype.initCustomCol = function () {
        var platform = this.platform();
        if (!platform)
            return;
        if (this.ad_custom_col_id == '')
            return;
        var size = platform.getSystemInfoSync();
        if (this.ad_customer_col == null) {
            this.ad_customer_col = platform.createCustomAd({
                adUnitId: this.ad_custom_col_id,
                adIntervals: 30,
                style: {
                    width: size.screenWidth - 20,
                    left: 10,
                    top: (size.screenHeight - 350) / 2,
                    fixed: 0
                }
            });
            this.ad_customer_col.onError(function (err) { });
        }
    };
    GbzSdkManager.prototype.showCustomCol = function (bool) {
        if (bool === void 0) { bool = true; }
        var platform = this.platform();
        if (!platform)
            return;
        if (this.ad_customer_col)
            bool ? this.ad_customer_col.show() : this.ad_customer_col.hide();
    };
    GbzSdkManager.prototype.getRank = function () {
        var platform = this.platform();
        if (!platform)
            return;
        platform.postMessage({
            event: 'getRank'
        });
    };
    GbzSdkManager.prototype.setRank = function (data) {
        var platform = this.platform();
        if (!platform)
            return;
        platform.postMessage({
            event: 'setRank',
            data: data
        });
    };
    GbzSdkManager._ins = null;
    return GbzSdkManager;
}());
exports.default = GbzSdkManager;

cc._RF.pop();